#pragma once
#include <cmath>
#define PI 3.1415926535

static void host_swap(float &a, float &b)
{
    float t = a;
    a = b;
    b = t;
}

static float host_max(float a, float b)
{
    return a > b ? a : b;
}

static float host_min(float a, float b)
{
    return a < b ? a : b;
}

static float host_clamp(const float &lo, const float &hi, const float &v)
{

    return host_max(lo, host_min(hi, v));
}

static bool hostSolveQuadratic(const float &a, const float &b, const float &c, float &x0, float &x1)
{
    float discr = b * b - 4 * a * c;
    if (discr < 0)
        return false;
    else if (discr == 0)
        x0 = x1 = -0.5 * b / a;
    else
    {
        float q = (b > 0) ? -0.5 * (b + std::sqrt(discr)) : -0.5 * (b - std::sqrt(discr));
        x0 = q / a;
        x1 = c / q;
    }

    if (x0 > x1)
    {
        float temp = x0;
        x0 = x1;
        x1 = temp;
    }
    // std::swap(x0, x1);
    return true;
}

static float clamp_host(const float &lo, const float &hi, const float &v)
{

    return host_max(lo, host_min(hi, v));
}
#define PI 3.1415926535

static float deg2rad_host(float deg)
{
    return deg / 180.f * PI;
}

static float tan_host(float rad)
{
    return tan(rad);
}

static float pow_host(float n, float m)
{
    return std::pow(n, m);
}
